<!--海外出库-波次计划-->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">

    </ex_super_table_page>

    <!-- <detail_standard_wavePlan ref="detail_standard_wavePlan" /> -->


  </div>
</template>
<script>
// import detail_standard_wavePlan from '@/component/wms/detail_standard_wavePlan.vue';

import superTablePageFunction from '@/mixin/super-table-page-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'standard>wave_plan_list'
export default {
  title: "title_standard_wave_plan",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: {},
  data() {
    return {
      selection: [],
      search_startDate: null,
      search_endDate: null,
      option: {
        search: {
          model: [
            { label: "label_wave_code", key: "waveNo", },
            { label: "label_outbound_code", key: "outOrderNo", },
            { label: "label_outbound_type", key: "outOrderType", type: 'select', enum: 'OutboundOrderTypeEnum' },
            { label: "label_sku", key: "skuId", type: "sku_selec_input" },
            {
              label: "label_wave_plan_create_time", key: "startDate", type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'endDate'; const limitValue = data[limitKey]; const value = data[item.key];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false } }}
                />)
              }
            },
            {
              label: "~", key: "endDate", type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const limitKey = 'startDate'; const limitValue = data[limitKey]; const value = data[item.key];
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime','default-time': '23:59:59' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false } }}
                />)
              }
            },
          ],
        },
        actionExtra: [
          { label: 'label_create_pick_task', attrs: { type: "primary" }, auth: 'wms_overseas_outbound_create_pick_task', click: this.createPickingTask },
        ],
        table: {
          url: "/wms-api/outbound/OutboundWavePlanRpc/selectListPage.json",
          model: this.init_table_model(),
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        { key: 'waveNo', label: 'label_wave_code', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'warehouseCode', label: 'label_outbound_warehouse', 'min-width': 100, 'show-overflow-tooltip': true, },
        { key: 'outOrderType', label: 'label_outbound_type', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "OutboundOrderTypeEnum") },
        { key: 'waveStatus', label: 'label_wave_status', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "WavePlanStatusEnum") },

        { key: 'printNumber', label: 'label_print_count', 'width': 80, },
        { key: 'orderCount', label: 'label_order_count', 'width': 80, },
        { key: 'skuTotalPiece', label: 'label_sku_total_count', 'width': 80, },
        {
          key: 'waveRule', label: 'label_wave_rule', 'min-width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => v ? v.split(',').map(it => this.$enumShow(it, 'WavePlanRuleEnum')).join(',') : ""
        },
        { key: 'gmtCreate', label: 'label_create_time', 'width': 120, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'creator', label: 'label_create_user', 'width': 100, 'show-overflow-tooltip': true, },

        {
          type: 'operate', 'width': 160, operate: [

            {
              label: "label_restore", auth: 'wms_overseas_outbound_wave_plan_restore',
              type: 'confirm-button', buttonClass: "button_text_warning", confirmButtonType: 'warning',
              disabled: (row) => !['WAIT_GENERATE', 'WAIT_ASSIGNED'].some(it => it == row.waveStatus),
              url: '/wms-api/outbound/OutboundWavePlanRpc/restoreWavePlan.json', message: 'text_confirm_sure_restore',
              params: (row) => { return { id: row.id } }, done: ['reload', 'tip', () => {
                this.$emitPage('standard>outbound_manage', 'reload')
              }]

            },
            {
              label: "label_view_detail",
              click: (row) => this.clickDetail(row)

            },
          ],
        },
      ]
    },
    createPickingTask(row) {
      let _list = this.selection
      if (_list.length == 0) {
        return this.$message.error(this.$tt('tip_please_select_order'))
      }
      if (_list.some(it => it.waveStatus != 'WAIT_GENERATE')) {
        let checkNoList = []
        _list.forEach(it => {
          if (it.waveStatus != 'WAIT_GENERATE') checkNoList.push(it)
        })
        this.$msgbox_table({

          note: [
            this.$tt('tip_only_WAIT_GENERATE_can_create_pick_task'),
            this.$tt('tip_part_order_status_error_no_operate'),
          ],
          tableProp: {
            data: checkNoList,
            'max-height': 500,
            model: [
              { key: 'waveNo', label: 'label_wave_code', 'min-width': 140, 'show-overflow-tooltip': true, },
              { key: 'waveStatus', label: 'label_wave_status', 'min-width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "WavePlanStatusEnum") },
            ]
          }
        }, { title: this.$tt('label_create_pick_task'), type: 'warning', customClass: 'dialog_small' })
        return
      }
      this.$confirm(this.$tt('text_is_sure_create_pick_task'), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.submitPickingTask(_list);
      }).catch(() => {
      });
    },
    submitPickingTask(list) {
      this.$ajax({
        url: "/wms-api/outbound/OutboundPickingTaskRpc/createPickingTaskByWavePlanIds.json",
        method: 'post',
        data: { wavePlanIds: _.join(list.map(it => it.id), ',') },
        loading: true,
        success: (res) => {
          this.$message.success(this.$tt('tip_submit_success'))
          this.reload()
        },
      })
    },
    clickDetail(row) {
      // let title = `${this.$tt('label_wave_code')}:${row.waveNo}`
      // this.$refs['detail_standard_wavePlan'].show({ params: { id: row.id }, title })

      this.$router.push({ path: '/page/wms/overseas/outbound/wave_plan_detail', query: { id: row.id, } })

    },
  }
};

</script>
<style></style>
